import { _decorator, Component, Label } from 'cc';
const { ccclass, inspector, property } = _decorator;

import * as cc from "cc";
import { VMCenter } from '../../framework/vm/VMCenter';
import { userData } from '../../game/storage/UserData';
import { VMBaseAttr, VMEntity } from '../../framework/vm/VMEntity';
import { mvvm, VMCustom, VMNode } from '../../framework/vm/VMDecorator';
import { DemoVMSceneBase } from './DemoVMSceneBase';

@ccclass('DemoVMCustom')
// @mvvm()
export default class DemoVMCustom extends  DemoVMSceneBase implements IMVVM{
    _vmTag: string = "DemoVMCustom";
    _vmEntitys: VMEntity[];


    // @VMCustom(cc.Label,{
    //     watchPath: 'userdata.atk', property: "color", formator(param) {
    //         if (param.newValue >= 15) {
    //             return cc.Color.RED;
    //         }
    //         return cc.Color.WHITE;
    //     }
    // })
    // @VMLabel({ watchPath: 'userdata.atk' })
    @property(Label)
    atkLabel: cc.Label = null;



    onLoad() {
    }
    start() {
        super.start();
    }


    onEnable(){
        VMCenter.add(userData,"userdata");

        VMCenter.Label(this,this.atkLabel,{watchPath: "userdata.atk"});
        
        VMCenter.Custom(this,cc.Label,this.atkLabel,{watchPath: "userdata.atk",property:"color",formator(opts){
            if (opts.newValue >= 5) {
                return cc.Color.RED;
            }
            return cc.Color.WHITE;
        }})


    }
    onDisable(){
        VMCenter.remove(this);
    }

    onClickAddAtk() {
        userData.atk ++;
    }

    onClickMulAtk() {
        userData.atk --;
    }
}

